#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>

#define CMD_LED_CLOSE _IO(0xef, 0x1)
#define CMD_LED_OPEN _IO(0xef, 0x2)
#define CMD_SET_PERIOD _IO(0xef, 0x3)

int main(int argc, char *argv[])
{
    int fd,ret;
    unsigned int cmd;
    unsigned int period;


    fd=open(argv[1], O_RDWR);
    if(fd<0){
        printf("ERROR: file %s open failed!\n", argv[1]);
        return -1;
    }

    for(;;){
        printf("Input CMD:");
        scanf("%d", &cmd);

        switch(cmd){
            case 0:
                cmd=CMD_LED_CLOSE;
                break;
            case 1:
                cmd=CMD_LED_OPEN;
                break;
            case 2:
                cmd=CMD_SET_PERIOD;
                printf("Input Timer Period:");
                scanf("%d", &period);
                break;
            case 3:
                close(fd);
                return 0;
            default:
                break;
        }

        ioctl(fd,cmd,period);
    }
}